<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Music/classes/PhpFox_ComponentViewAlbum.class.php, $Author:  $ */



/** Component for viewing album
 *
 * @version $Id: PhpFox_ComponentViewAlbum.class.php 395 2008-03-04 22:39:40Z phpfoxsv $
 * @package module.music
 */
class PhpFox_Mod_Music_ComponentViewAlbum extends BaseComponent
{
    function process()
    {
        $oMusicService = &$this->_oModule->getService('Music');
        /* @var $oMusicService PhpFox_Mod_Music_ServiceMusic */
        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();

        $oSecurityService->checkPerm('music', array('read_only', 'full'));
        $oSecurityService->checkAccess('music');
        $oCurrUser = $oSecurityService->getCurrentUser();
        $iAlbumId = $oReq->getInt('id');
        $aCond = array
        (
            'album_id' => '= '.$iAlbumId,
        );
        list($aAlbum) = $oMusicService->getAlbumsList($aCond);
        if (!count($aAlbum))
        {
            App::gotoUrl('public.music');
        }
        $aAlbum = $aAlbum[0];
        if (!$aAlbum['album_is_approved'])
        {
            App::gotoUrl('public.music');
        }

        $bStaff = $oSecurityService->isStaff();
        if ($oReq->get('delete'))
        {
            if ($bStaff)
            {
                $oMusicService->deleteAlbum($iAlbumId);
            }
            App::gotoUrl('public.music');
        }
        if ($iSongId = $oReq->getInt('makefeatured'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId);
            }
            App::gotoUrl('', array('id' => $iAlbumId));
        }
        if ($iSongId = $oReq->getInt('deletefeatured'))
        {
            if ($bStaff)
            {
                $oMusicService->setSongFeaturedState($iSongId, false);
            }
            App::gotoUrl('', array('id' => $iAlbumId));
        }
        if ($iSongId = $oReq->get('makeaccount'))
        {
            if(!$oCurrUser)
        		App::gotoUrl('public.login');
            $oMusicService->setActualAccountMusic($iSongId);
            App::gotoUrl('', array('id' => $iAlbumId));
        }
        if ($iSongId = $oReq->getInt('makefavorite'))
        {
            if(!$oCurrUser)
        		App::gotoUrl('public.login');
            if ($oMusicService->makeSongFavorite($iSongId))
            {
                App::gotoUrl('public.account.favorites');
            }
            App::gotoUrl('', array('id' => $iAlbumId));
        }

        if (App::getParam('bSongSecurity'))
		{
        	App::clearAccessForContent('music');
		}        
        $aCond['song_is_approved'] = '= 1';
        $sSongs = '';
        list($aSongsList, $iCnt) = $oMusicService->getSongsList($aCond, 0, 0, 'song_title');
        foreach ($aSongsList as $iKey => $aSong)
        {
            $aSongsList[$iKey]['song_is_favorite'] = $oMusicService->isSongFavorite($aSong['song_id']);
            $aSongsList[$iKey]['song_is_actual']   = $oMusicService->isSongActual($aSong['song_id']);
            $aSongsList[$iKey]['song_owner'] 	   = ($aSong['user_id'] == App::getUser('id') ? true : false);
            if (App::getParam('bSongSecurity'))
			{
				App::setAccessForContent('music', $aSong['song_id']);
			}
            $sSongs .= $aSong['song_id'].',';
        }
        $sSongs = rtrim($sSongs, ',');

        $oTpl->assign(array(
            'aSongsList' => $aSongsList,
            'aAlbum'     => $aAlbum,
            'sSongs' => $iAlbumId,
            'bStaff'     => $bStaff,
            'sAlbumsUrl' => App::getParam('music.album.pic.url'),
            'oCurrUser'  => $oSecurityService->getCurrentUser(),
            'iCnt' => $iCnt
        ));
        return $oTpl->fetch('ViewAlbum.html');
    }
}
?>